package com.bbz.spring.bean;

import org.springframework.beans.factory.FactoryBean;

//创建一个Spring Factory Bean
public class ColorFactoryBean implements FactoryBean<Color> {
    private String name;

    public ColorFactoryBean(String name) {
        this.name = name;
    }

    public ColorFactoryBean() {
    }


    //返回一个Color对象，这个对象会注册到容器中
    @Override
    public Color getObject() throws Exception {
        if(name.equals("Green")){
            return new Green(name,10);
        }
        return new Color();
    }

    //返回对象类型。
    @Override
    public Class<?> getObjectType() {
        return Color.class;
    }

    //是否单例Bean
    @Override
    public boolean isSingleton(){
        return true;
    }
}
